//
//  HGDividendDetailVC.m
//  RedWinMall
//
//  Created by HeDianZhao on 2018/8/8.
//  Copyright © 2018年 HeDianZhao. All rights reserved.
//

#import "HGDividendDetailVC.h"
#import "HGDividendDetailCell.h"
#import "HGFansModel.h"

@interface HGDividendDetailVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic,strong)UITableView* tableView;

@property (nonatomic,strong)NSMutableArray<HGFansModel *>* models;

@end

@implementation HGDividendDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"分红明细";
    
    [self initDatas];
    
    [self.tableView registerClass:[HGDividendDetailCell class] forCellReuseIdentifier:@"HGDividendDetailCell"];
}

#pragma mark -
- (void)initDatas {
    [[LMJRequestManager sharedManager] GET:KBaseURL(@"app/acct/flow/daily") parameters:@{@"date":_dateStr} completion:^(LMJBaseResponse *response) {
        if (response.responseModel.status == 1) {
            NSArray *arr = [HGFansModel mj_objectArrayWithKeyValuesArray:response.responseModel.data[@"infoVos"]];
            [arr enumerateObjectsUsingBlock:^(HGFansModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.date = _dateStr;
            }];
            [self.models addObjectsFromArray:arr];
            [_tableView reloadData];
        }
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HGDividendDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HGDividendDetailCell"];
    cell.model = _models[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _models.count;
}

- (UITableView *)tableView {
    if (!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 83;
        _tableView.tableFooterView = [UIView new];
        [self.view addSubview:_tableView];
        
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
    }
    return _tableView;
}

- (NSMutableArray<HGFansModel *> *)models {
    if (!_models) {
        _models = [@[] mutableCopy];
    }
    return _models;
}

@end
